﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NasuTek.Shion.Extencibility;
using iTunesLib;

namespace Shion.iTunesNowPlayingPlugin
{
    public class Plugin : IPlugin
    {
        #region IPlugin Members

        public void Load(ExtencibilityManager e)
        {
            e.Plugins.Add("ItunesNP", new ExtencibilityManager.PluginData("iTunes Now Playing Plugin",
                "(C) 2009 NasuTek Systems",
                "NasuTek Systems",
                "Allows you to type /exe np to show currently played song",
                GetType().Assembly.GetName().Version));

            e.Aliases.Add("np", new NowPlaying());
        }

        #endregion
    }

    public class NowPlaying : Alias
    {
        #region Alias Members

        public void Execute(string[] args, Dictionary<string, string> vars, ExtencibilityManager ex)
        {
            iTunesApp app = new iTunesAppClass();
            IITTrack trackInfo = app.CurrentTrack;

            string songReturn = String.Format("is listening to \"{0}\" by {1}, from the album {2}. [{3} mins] [played {4} times]", new object[] { trackInfo.Name, trackInfo.Artist, trackInfo.Album, trackInfo.Time, trackInfo.PlayedCount });

            ex.Clients[vars["em.activeServer"]].SendMessage(NasuTek.Shion.Agent.SendType.Action, vars["em.activeChannel"], songReturn);
        }

        #endregion
    }

}
